package com.colourclash.fruitopia.particles 
{
	import com.colourclash.fruitopia.utils.Global;
	import com.greensock.TweenLite;
	import flash.display.Sprite;
	import flash.geom.Point;
	/**
	 * Container for particle effects
	 * @author Patrick Hammond
	 */
	public class ParticleEffect extends Sprite
	{
		private var _particle:Sprite;
		
		public function ParticleEffect(type:Class, position:Point, duration:Number) 
		{
			_particle = new type(position) as Sprite;
			addChild(_particle);
			TweenLite.delayedCall(duration, stopParticleEffect);
			TweenLite.delayedCall(duration + 1, destroyParticleEffect);
		}
		
		private function stopParticleEffect():void 
		{
			(_particle as IParticleEffect).stop();
		}
		
		private function destroyParticleEffect():void 
		{
			(_particle as IParticleEffect).destroy();
			parent.removeChild(this);
		}
		
	}

}